# version 3.19 -> 3.16
# 默认的最⼩版本是 3.5，⾼版本, 否则后⾯可能会⽣成失败!
cmake_minimum_required(VERSION 3.16)
project(ChatClient LANGUAGES CXX)

# 1. 首先查找 Qt6 核心包，不指定组件
find_package(Qt6 6.5 REQUIRED)

# 2. 分别查找所需的 Qt6 组件
find_package(Qt6 COMPONENTS Core REQUIRED)
find_package(Qt6 COMPONENTS Widgets REQUIRED)
find_package(Qt6 COMPONENTS Protobuf REQUIRED) # 引入Protobuf
find_package(Qt6 COMPONENTS Network WebSockets REQUIRED) # 引入网络库
find_package(Qt6 REQUIRED COMPONENTS Core)

qt_standard_project_setup()

qt_add_executable(ChatClient
    WIN32 MACOSX_BUNDLE
    main.cpp
    mainwidget.cpp
    mainwidget.h
    mainwidget.ui
    model/data.h
    resource.qrc
    sessionfriendarea.h sessionfriendarea.cpp
    debug.h
    messageshowarea.h messageshowarea.cpp
    messageeditarea.h messageeditarea.cpp
    selfinfowidget.h selfinfowidget.cpp
    userinfowidget.h userinfowidget.cpp
    userinfowidget.h userinfowidget.cpp
    sessiondetailwidget.h sessiondetailwidget.cpp
    choosefrienddialog.h choosefrienddialog.cpp
    publicmethods.h publicmethods.cpp
    groupsessiondetailwidget.h groupsessiondetailwidget.cpp
    addfrienddialog.h addfrienddialog.cpp
    historymessagewidget.h historymessagewidget.cpp
    loginwidget.h loginwidget.cpp
    verifycodewidget.h verifycodewidget.cpp
    phoneloginwidget.h phoneloginwidget.cpp
    toast.h toast.cpp
    network/netclient.h network/netclient.cpp

)

# 识别导入的proto文件，将文件名保存在PB_FILES
file(GLOB PB_FILES "./proto/*.proto")
# 引入proto文件到项目
qt_add_protobuf(ChatClient PROTO_FILES ${PB_FILES})

# 添加资源文件
set(QRC_FILES
    resource.qrc
)

# 编译资源文件
qt_add_resources(RESOURCES_CPP ${QRC_FILES})

# 将资源文件加入目标
target_sources(ChatClient PRIVATE ${RESOURCES_CPP})

target_link_libraries(ChatClient
    PRIVATE
        Qt::Core
        Qt::Widgets
)

# 连接程序所需动态库
target_link_libraries(ChatClient PRIVATE Qt6::Widgets)
target_link_libraries(ChatClient PRIVATE Qt6::Protobuf)
target_link_libraries(ChatClient PRIVATE Qt6::Network)
target_link_libraries(ChatClient PRIVATE Qt6::WebSockets)
target_link_libraries(ChatClient PRIVATE Qt6::Core)

include(GNUInstallDirs)

install(TARGETS ChatClient
    BUNDLE  DESTINATION .
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

qt_generate_deploy_app_script(
    TARGET ChatClient
    OUTPUT_SCRIPT deploy_script
    NO_UNSUPPORTED_PLATFORM_ERROR
)
install(SCRIPT ${deploy_script})
